# 导包
import pymysql

# 创建连接
conn = pymysql.connect(host="localhost", port=3306, user="root",
                       password="10086", database="student", charset="utf8")

# 创建游标
my_cursor = conn.cursor()

# 执行 select sql
my_cursor.execute("select * from course;")

# 提取结果,打印查看
res = my_cursor.fetchone()
#游标归零
my_cursor.rownumber = 0
res2 =my_cursor.fetchall()
print("查询结果为：", res)
print("查询结果为：", res2)

my_cursor.rownumber=2
res3=my_cursor.fetchmany(2)
print("查询结果为:",res3)
# 关闭游标
my_cursor.close()

# 关闭连接
conn.close()